package com.tsystems.skilltest;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
 * @author aesipov
 */
public class CSVParser
{
    public List<Transaction> parse(String filePath) throws IOException
    {
        List<Transaction> result = new ArrayList<Transaction>();
        BufferedReader reader = new BufferedReader(new FileReader(filePath));

        String line;
        while ((line = reader.readLine()) != null)
        {
            StringTokenizer tokenizer = new StringTokenizer(line, ",");
            String clientName = tokenizer.nextToken().trim();
            int accountNumber = Integer.parseInt(tokenizer.nextToken().trim());
            int value = Integer.parseInt(tokenizer.nextToken().trim());
            Transaction transaction = new Transaction(clientName, accountNumber, value);
            result.add(transaction);
        }

        return result;
    }
}
